package com.airsystem.pos.bengkel.view;

import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Toolkit;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

import javax.swing.BorderFactory;
import javax.swing.ImageIcon;

import org.jdesktop.layout.GroupLayout;
import org.jdesktop.layout.LayoutStyle;

import com.airsystem.pos.bengkel.controller.MenuController;

/**
 * @author Budi Oktaviyan <budi.oktaviyan@icloud.com>
 */
public class Menu extends MenuController {

	public Menu() {
		super();

		this.setIconImage(new ImageIcon(getClass().getResource("/images/logo.png")).getImage());
		initComponents();
		timer();
	}

	private void initComponents() {
		setTitle("Auto Mandiri - Service Station v1.3");

		addWindowListener(new WindowAdapter() {
			public void windowClosing(WindowEvent evt) {
				windowClosingEvent(evt);
			}
		});

		desktopPane.setBackground(Color.gray);
		statusPane.setBorder(BorderFactory.createEtchedBorder(new Color(153, 153, 153), null));

		getContentPane().add(desktopPane, BorderLayout.CENTER);
		getContentPane().add(statusPane, BorderLayout.PAGE_END);

		systemMenu.setFont(new Font("Verdana", 1, 14));
		systemMenu.setText("Sistem");

		masterMenu.setFont(new Font("Verdana", 1, 14));
		masterMenu.setText("Data");

		transactionMenu.setFont(new Font("Verdana", 1, 14));
		transactionMenu.setText("Transaksi");

		reportMenu.setFont(new Font("Verdana", 1, 14));
		reportMenu.setText("Laporan");

		itemUserManagement.setIcon(new ImageIcon(getClass().getResource("/images/admin.png")));
		itemUserManagement.setFont(new Font("Verdana", 0, 14));
		itemUserManagement.setText("Data User");

		itemUserManagement.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				itemUserManagementPerformed(evt);
			}
		});

		itemChangePassword.setIcon(new ImageIcon(getClass().getResource("/images/password.png")));
		itemChangePassword.setFont(new Font("Verdana", 0, 14));
		itemChangePassword.setText("Ganti Password");

		itemChangePassword.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				itemChangePasswordPerformed(evt);
			}
		});

		itemLogout.setIcon(new ImageIcon(getClass().getResource("/images/logout.png")));
		itemLogout.setFont(new Font("Verdana", 0, 14));
		itemLogout.setText("Logout");

		itemLogout.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				itemLogoutPerformed(evt);
			}
		});

		itemEmployee.setIcon(new ImageIcon(getClass().getResource("/images/user.png")));
		itemEmployee.setFont(new Font("Verdana", 0, 14));
		itemEmployee.setText("Data Karyawan");

		itemEmployee.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				itemEmployeePerformed(evt);
			}
		});

		itemBilling.setIcon(new ImageIcon(getClass().getResource("/images/wallet.png")));
		itemBilling.setFont(new Font("Verdana", 0, 14));
		itemBilling.setText("Data Jenis Tagihan");

		itemBilling.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				itemBillingPerformed(evt);
			}
		});

		itemBillingDetail.setIcon(new ImageIcon(getClass().getResource("/images/walletx.png")));
		itemBillingDetail.setFont(new Font("Verdana", 0, 14));
		itemBillingDetail.setText("Data Tagihan Bulanan");

		itemBillingDetail.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				itemBillingDetailPerformed(evt);
			}
		});

		itemVehicle.setIcon(new ImageIcon(getClass().getResource("/images/vehicle.png")));
		itemVehicle.setFont(new Font("Verdana", 0, 14));
		itemVehicle.setText("Data Kendaraan");

		itemVehicle.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				itemVehiclePerformed(evt);
			}
		});

		itemCustomer.setIcon(new ImageIcon(getClass().getResource("/images/customer.png")));
		itemCustomer.setFont(new Font("Verdana", 0, 14));
		itemCustomer.setText("Data Pelanggan");

		itemCustomer.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				itemCustomerPerformed(evt);
			}
		});

		itemSparepartType.setIcon(new ImageIcon(getClass().getResource("/images/sparepart.png")));
		itemSparepartType.setFont(new Font("Verdana", 0, 14));
		itemSparepartType.setText("Data Jenis Sparepart");

		itemSparepartType.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				itemSparepartTypePerformed(evt);
			}
		});

		itemSparepart.setIcon(new ImageIcon(getClass().getResource("/images/sparepartx.png")));
		itemSparepart.setFont(new Font("Verdana", 0, 14));
		itemSparepart.setText("Data Sparepart");

		itemSparepart.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				itemSparepartPerformed(evt);
			}
		});

		itemJasaType.setIcon(new ImageIcon(getClass().getResource("/images/jasa.png")));
		itemJasaType.setFont(new Font("Verdana", 0, 14));
		itemJasaType.setText("Data Jenis Service");

		itemJasaType.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				itemJasaTypePerformed(evt);
			}
		});

		itemJasa.setIcon(new ImageIcon(getClass().getResource("/images/jasax.png")));
		itemJasa.setFont(new Font("Verdana", 0, 14));
		itemJasa.setText("Data Service");

		itemJasa.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				itemJasaPerformed(evt);
			}
		});

		itemSparepartOrder.setIcon(new ImageIcon(getClass().getResource("/images/spareparty.png")));
		itemSparepartOrder.setFont(new Font("Verdana", 0, 14));
		itemSparepartOrder.setText("Pesan Sparepart");

		itemSparepartOrder.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				itemSparepartOrderPerformed(evt);
			}
		});

		itemJasaOrder.setIcon(new ImageIcon(getClass().getResource("/images/jasay.png")));
		itemJasaOrder.setFont(new Font("Verdana", 0, 14));
		itemJasaOrder.setText("Jasa Service");

		itemJasaOrder.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				itemJasaOrderPerformed(evt);
			}
		});

		itemEmployeeReport.setIcon(new ImageIcon(getClass().getResource("/images/userx.png")));
		itemEmployeeReport.setFont(new Font("Verdana", 0, 14));
		itemEmployeeReport.setText("Laporan Data Karyawan");

		itemEmployeeReport.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				itemEmployeeReportPerformed(evt);
			}
		});

		itemBillingReport.setIcon(new ImageIcon(getClass().getResource("/images/wallety.png")));
		itemBillingReport.setFont(new Font("Verdana", 0, 14));
		itemBillingReport.setText("Laporan Tagihan Bulanan");

		itemBillingReport.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				itemBillingReportPerformed(evt);
			}
		});

		itemSparepartDebit.setIcon(new ImageIcon(getClass().getResource("/images/sparepartz.png")));
		itemSparepartDebit.setFont(new Font("Verdana", 0, 14));
		itemSparepartDebit.setText("Laporan Pesanan Sparepart");

		itemSparepartDebit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				itemSparepartDebitPerformed(evt);
			}
		});

		itemCustomerCredit.setIcon(new ImageIcon(getClass().getResource("/images/customerx.png")));
		itemCustomerCredit.setFont(new Font("Verdana", 0, 14));
		itemCustomerCredit.setText("Laporan Penjualan");

		itemCustomerCredit.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				itemCustomerCreditPerformed(evt);
			}
		});

		itemBalanceSheet.setIcon(new ImageIcon(getClass().getResource("/images/balance.png")));
		itemBalanceSheet.setFont(new Font("Verdana", 0, 14));
		itemBalanceSheet.setText("Laporan Balance Sheet");

		itemBalanceSheet.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent evt) {
				itemBalanceSheetPerformed(evt);
			}
		});

		timeLabel.setFont(new Font("Verdana", 1, 12));

		systemMenu.add(itemUserManagement);
		systemMenu.add(itemChangePassword);
		systemMenu.add(systemSeparator);
		systemMenu.add(itemLogout);

		masterMenu.add(itemEmployee);
		masterMenu.add(itemBilling);
		masterMenu.add(itemBillingDetail);
		masterMenu.add(masterSeparator);
		masterMenu.add(itemVehicle);
		masterMenu.add(itemCustomer);
		masterMenu.add(itemSparepartType);
		masterMenu.add(itemSparepart);
		masterMenu.add(itemJasaType);
		masterMenu.add(itemJasa);

		transactionMenu.add(itemSparepartOrder);
		transactionMenu.add(itemJasaOrder);

		reportMenu.add(itemEmployeeReport);
		reportMenu.add(itemBillingReport);
		reportMenu.add(reportSeparator);
		reportMenu.add(itemSparepartDebit);
		reportMenu.add(itemCustomerCredit);
		reportMenu.add(itemBalanceSheet);

		menuBar.add(systemMenu);
		menuBar.add(masterMenu);
		menuBar.add(transactionMenu);
		menuBar.add(reportMenu);
		setJMenuBar(menuBar);

		GroupLayout statusLayout = new GroupLayout(statusPane);
		statusPane.setLayout(statusLayout);
		statusLayout.setHorizontalGroup(statusLayout.createParallelGroup(GroupLayout.LEADING)
					.add(statusLayout.createSequentialGroup()
					.addPreferredGap(LayoutStyle.RELATED, 550, Short.MAX_VALUE).add(timeLabel)
					.add(10, 10, 10)));

		statusLayout.setVerticalGroup(statusLayout.createParallelGroup(GroupLayout.LEADING)
					.add(statusLayout.createParallelGroup(GroupLayout.BASELINE)
					.add(timeLabel)));

		Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
		setSize(screenSize.width, screenSize.height);
		setLocationRelativeTo(this);
	}

	private void windowClosingEvent(WindowEvent evt) {
		exit();
	}

	private void itemUserManagementPerformed(ActionEvent evt) {
		openUserManagement();
	}

	private void itemChangePasswordPerformed(ActionEvent evt) {
		openChangePassword();
	}

	private void itemLogoutPerformed(ActionEvent evt) {
		logout();
	}

	private void itemEmployeePerformed(ActionEvent evt) {
		openMasterEmployee();
	}

	private void itemBillingPerformed(ActionEvent evt) {
		openMasterBilling();
	}

	private void itemBillingDetailPerformed(ActionEvent evt) {
		openMasterBillingDetail();
	}

	private void itemVehiclePerformed(ActionEvent evt) {
		openMasterVehicle();
	}

	private void itemCustomerPerformed(ActionEvent evt) {
		openMasterCustomer();
	}

	private void itemSparepartTypePerformed(ActionEvent evt) {
		openMasterSparepartType();
	}

	private void itemSparepartPerformed(ActionEvent evt) {
		openMasterSparepart();
	}

	private void itemJasaTypePerformed(ActionEvent evt) {
		openMasterJasaType();
	}

	private void itemJasaPerformed(ActionEvent evt) {
		openMasterJasa();
	}

	private void itemSparepartOrderPerformed(ActionEvent evt) {
		openSparepartOrder();
	}

	private void itemJasaOrderPerformed(ActionEvent evt) {
		openJasaOrder();
	}

	private void itemEmployeeReportPerformed(ActionEvent evt) {
		openEmployeeReport();
	}

	private void itemBillingReportPerformed(ActionEvent evt) {
		openBillingReport();
	}

	private void itemSparepartDebitPerformed(ActionEvent evt) {
		openSparepartDebit();
	}

	private void itemCustomerCreditPerformed(ActionEvent evt) {
		openCustomerCredit();
	}

	private void itemBalanceSheetPerformed(ActionEvent evt) {
		openBalanceSheet();
	}
}